package com.himore.api.web.controller.modules;

import java.util.List;

import com.himore.api.common.annotation.Log;
import com.himore.api.common.constant.HttpStatus;
import com.himore.api.common.core.controller.BaseController;
import com.himore.api.common.core.domain.AjaxResult;
import com.himore.api.common.core.domain.entity.SysUser;
import com.himore.api.common.core.page.TableDataInfo;
import com.himore.api.common.enums.BusinessType;
import com.himore.api.common.utils.ErrorCodeUtil;
import com.himore.api.common.utils.SecurityUtils;
import com.himore.api.common.utils.StringUtils;
import com.himore.api.common.utils.poi.ExcelUtil;
import com.himore.api.web.model.TSysComment;
import com.himore.api.web.model.TSysCommentVO;
import com.himore.api.web.service.ITSysCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import static com.himore.api.common.core.domain.AjaxResult.error;


/**
 * 评论信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-12
 */
@Api(tags = "评论管理")
@Controller
@RequestMapping("/system/comment")
public class TSysCommentController extends BaseController
{
    private String prefix = "system/comment";

    @Autowired
    private ITSysCommentService tSysCommentService;

    @GetMapping()
    public String comment()
    {
        return prefix + "/comment";
    }

    /**
     * 查询评论信息列表
     */
    @ApiOperation(value = "查询评论信息列表", notes = "查询评论信息列表", produces = "application/json")
    @Log(title = "查询评论信息", businessType = BusinessType.QUERY)
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody TSysComment tSysComment)
    {
        try {
            SysUser sysUser = SecurityUtils.getLoginUserInfo().getUser();
            tSysComment.setUserId(sysUser.getUserId());
        }catch (Exception e){
        }
        startPage();
        if(tSysComment.getPageNo()!=0 && tSysComment.getPageSizes() !=0){
           int  start  = (tSysComment.getPageNo()-1)* tSysComment.getPageSizes();
            tSysComment.setPageStart(start);
        }
        List<TSysCommentVO> list = tSysCommentService.selectTSysCommentList(tSysComment);
        return getDataTable(list);
    }




    /**
     * 新增保存评论信息
     */
    @ApiOperation(value = "新增评论信息", notes = "新增评论信息", produces = "application/json")
    @Log(title = "评论信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody TSysComment tSysComment)
    {
        if(StringUtils.isBlank(tSysComment.getCommentDetail())){
            return error(ErrorCodeUtil.E_101,"您输入的评论信息为空，请重新输入！");
        }
        if(StringUtils.isBlank(tSysComment.getInvitationId())){
            return error(ErrorCodeUtil.E_101,"您输入的帖子ID为空，请重新输入！");
        }
        SysUser user =  SecurityUtils.getLoginUser().getUser();
        tSysComment.setUserId(user.getUserId());
        return new AjaxResult(HttpStatus.SUCCESS,"添加成功",tSysCommentService.insertTSysComment(tSysComment));
    }


    /**
     * 修改保存评论信息
     */
    @ApiOperation(value = "修改评论信息", notes = "修改评论信息", produces = "application/json")
    @Log(title = "评论信息修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSysComment tSysComment)
    {
        return toAjax(tSysCommentService.updateTSysComment(tSysComment));
    }

    /**
     * 删除评论信息
     */
    @ApiOperation(value = "删除评论信息", notes = "删除评论信息", produces = "application/json")
    @Log(title = "评论信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tSysCommentService.deleteTSysCommentByIds(ids));
    }
}
